<?php
	include("../connect/connect_dsccmis.php");
	
	//แปลงประเภทเหตุการณ์จาก evntypid จาก evnrelevntyp ไปเป็น mis_evntypid โดยใช้ตาราง convert_evntype
	$sql = "drop table if exists mis_event_type;";
	$rs=mysql_query($sql);
    $sql="create table mis_event_type as select e1.evnid,e1.evndte,left(e1.evnplcidgen,2) as prov,cdscc,e2.mis_evntypid from dscc.viewevent e1 left join  (select e1.evnid,min(e3.mis_evntypid) as mis_evntypid from dscc.viewevent e1 left join dscc.evnrelevntyp e2 on e1.evnid=e2.evnid left join convert_evntyp e3 on e2.evntypid=e3.evntypid group by e1.evnid) e2 on e1.evnid=e2.evnid left join dscc.TempEventAndCaseOfEvent e3 on e1.evnid=e3.evnid where left(e1.evnplcidgen,2) in ('94','95','96') or left(e1.evnplcidgen,4) in ('9003','9004','9005','9006')";
	
	$rs=mysql_query($sql);
	//mysql_free_result($rs);
	//mysql_close($c);
	echo "<br>complete create mis_event_type on dsccmis";
?>